/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmDangKyHocPhan.java
 *
 * Created on Feb 20, 2013, 9:42:17 PM
 */
package design;

import Dao.DangkiHP;
import Dao.HocPhanDao;
import Dao.Sinhvien;
import Entity.HocPhanEntity;
import Util.ConSQL;
import Util.Util;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Thuyngaytho
 */
public class frmDangKyHocPhan extends javax.swing.JFrame {

    DangkiHP dangkiHP = new DangkiHP();
    Vector tableRecord = new Vector();
    Vector tableTitle = new Vector();
    ConSQL conn = new ConSQL();
    Sinhvien sinhvien = new Sinhvien();
    DefaultComboBoxModel comboBoxModel;
    DefaultTableModel tableModel;
    private ArrayList<HocPhanEntity> arrHocPhan;
    private HocPhanDao hpDao = new HocPhanDao();
    private HocPhanEntity hpEntity;
    private Util util = new Util();
    private DefaultTableModel tableKetQua;

    /** Creates new form frmDangKyHocPhan */
    public frmDangKyHocPhan() throws Exception {
        initComponents();
        this.setSize(1200, 700);
    
        //
        loadKhoa();
        loadNienKhoa();
        LoadInformotion();
        loadKetQuaHP();

      
    }

    public frmDangKyHocPhan(String MaSV, String Hoten, String LopSH, String NienKhoa) throws Exception {
        initComponents();
        //cai dat cac thong tin cho form

        this.setSize(1200, 700);
        lbMaSV.setText(MaSV);
        lbTenSV.setText(Hoten);
        lbTenlop.setText(LopSH);
        lbNienkhoa.setText(NienKhoa);
        //
        loadKhoa();
        loadNienKhoa();
        LoadInformotion();
        loadKetQuaHP();

        if (dangkiHP.trangthaiDangkiHP().equals("1")) {
            btnDangKy.setEnabled(true);
        } else {
            btnDangKy.setEnabled(false);
        }
        //
        if (dangkiHP.trangthaiHuyHP().equals("1")) {
            btnHuyHP.setEnabled(true);
        } else {
            btnHuyHP.setEnabled(false);
        }
        //cai dat cac cbb
        cbbKhoa.setSelectedItem(dangkiHP.layTenkhoaByMaSV(MaSV));
        cbbNK.setSelectedItem(NienKhoa);

        cbbKhoa.setEnabled(false);
        cbbNK.setEnabled(false);

    }

    public void LoadInformotion() {
        tableModel = new DefaultTableModel();
        tableModel.setRowCount(0);

        Vector col = new Vector();
        col.addElement("Mã Lớp");
        col.addElement("Tên Lớp");
        col.addElement("Khoa");
        col.addElement("Môn học");
        col.addElement("Niên khóa");
        col.addElement("Tên giáo viên");
        col.addElement("Ngày bắt đầu");
        col.addElement("Ngày kết thúc");
        col.addElement("Số sinh viên");
        tableModel.setColumnIdentifiers(col);
        arrHocPhan = hpDao.getAll();
        for (int i = 0; i < arrHocPhan.size(); i++) {
            hpEntity = arrHocPhan.get(i);
            Vector row = new Vector();
            row.addElement(hpEntity.getMalopHP());
            row.addElement(hpEntity.getTenlopHP());
            row.addElement(hpEntity.getMakhoa());
            row.addElement(hpEntity.getMaMH());
            row.addElement(hpEntity.getMaNK());
            row.addElement(hpEntity.getMaGV());
            row.addElement(hpEntity.getNgayBD());
            row.addElement(hpEntity.getNgayKT());
            row.addElement(hpEntity.getSoSV());

            tableModel.addRow(row);
        }
        tbContent.setModel(tableModel);
    }

    private void loadKhoa() {
        comboBoxModel = new DefaultComboBoxModel();
        try {
            PreparedStatement ps = ConSQL.getCon().prepareStatement("select tenkhoa from khoa");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                comboBoxModel.addElement(rs.getString("tenkhoa"));
            }
            cbbKhoa.setModel(comboBoxModel);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    private void loadNienKhoa() {
        comboBoxModel = new DefaultComboBoxModel();
        try {
            PreparedStatement ps = ConSQL.getCon().prepareStatement("select tenNK from nienKhoa");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                comboBoxModel.addElement(rs.getString("tenNK"));
            }
            cbbNK.setModel(comboBoxModel);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    private void loadHocKy() {
        comboBoxModel = new DefaultComboBoxModel();
        try {
            PreparedStatement ps = ConSQL.getCon().prepareStatement("select tenNK from nienKhoa");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                comboBoxModel.addElement(rs.getString("tenNK"));
            }
            cbbNK.setModel(comboBoxModel);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    private void loadKetQuaHP() {
        String str = "";
        try {
            String sql = "select lopHP.tenLopHP, sinhVien.hoTen, monHoc.tenMH, lopHP.ngayBatdau, lopHP.ngayKetthuc, "
                    + "giaoVien.tenGV from lopHP, sinhVien, monHoc, giaoVien, lopHP_SV where sinhVien.maSV = lopHP_SV.maSV "
                    + "and lopHP.maLopHP = lopHP_SV.maLopHP and lopHP.maMH = monHoc.maMH and lopHP.maGV = giaoVien.maGV";

            PreparedStatement ps = ConSQL.getCon().prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                str = str + rs.getString("tenLopHP") + "~";
                str = str + rs.getString("hoTen") + "~";
                str = str + rs.getString("tenMH") + "~";
                str = str + rs.getString("ngayBatdau") + "~";
                str = str + rs.getString("ngayKetthuc") + "~";
                str = str + rs.getString("tenGV") + "~";
                str = str + "==";
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        tableKetQua = new DefaultTableModel();
        tableKetQua.setRowCount(0);
        Vector col = new Vector();
        col.addElement("Tên Lớp Học Phần");
        col.addElement("Họ Tên");
        col.addElement("Tên Môn Học");
        col.addElement("Ngày bắt đầu");
        col.addElement("Ngày kết thúc");
        col.addElement("Tên Giáo Viên");
        tableKetQua.setColumnIdentifiers(col);
        String[] strSpilit = str.split("==");
        String[] res, res1;
        for (int i = 0; i < strSpilit.length; i++) {
            res = strSpilit[i].split("!!");
            
            for (int j = 0; j < res.length; j++) {
                Vector row = new Vector();
                //System.out.println("asd: " + res[j]);
                res1 = res[j].split("~");
                for (int k = 0; k < res1.length; k++) {
                    
                    //System.out.println("qwe: " + res1[k]);
                    row.addElement(res1[k]);
                }
                 tableKetQua.addRow(row);
            }
        }
        tbContent.setModel(tableKetQua);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lbMaSV = new javax.swing.JLabel();
        lbTenSV = new javax.swing.JLabel();
        lbTenlop = new javax.swing.JLabel();
        lbNienkhoa = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        cbbKhoa = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        cbbNK = new javax.swing.JComboBox();
        btnLietke = new javax.swing.JButton();
        btnSearch = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        tfSearch = new javax.swing.JTextField();
        btnXemTKB = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbContent = new javax.swing.JTable();
        btnDangKy = new javax.swing.JButton();
        btnHuyHP = new javax.swing.JButton();
        btnThoat = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 255));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin sinh viên", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 0, 18))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel1.setText("Mã sinh viên :");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("Tên sinh viên :");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("Tên lớp :");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel4.setText("Niên khóa :");

        lbMaSV.setFont(new java.awt.Font("Tahoma", 0, 12));
        lbMaSV.setText("Mã");

        lbTenSV.setFont(new java.awt.Font("Tahoma", 0, 12));
        lbTenSV.setText("Tên");

        lbTenlop.setFont(new java.awt.Font("Tahoma", 0, 12));
        lbTenlop.setText("Tên lớp");

        lbNienkhoa.setFont(new java.awt.Font("Tahoma", 0, 12));
        lbNienkhoa.setText("Niên khóa");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbNienkhoa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbTenSV, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbMaSV, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                    .addComponent(lbTenlop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(85, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lbMaSV))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lbTenSV))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(lbTenlop))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(lbNienkhoa))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin tìm kiếm", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 0, 12))); // NOI18N

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel9.setText("Khoa :");

        cbbKhoa.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel5.setText("Khóa :");

        cbbNK.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btnLietke.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnLietke.setText("Liệt kê các lớp có thể đăng ký");
        btnLietke.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLietkeActionPerformed(evt);
            }
        });

        btnSearch.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Search-icon.png"))); // NOI18N
        btnSearch.setText("Tìm kiếm");
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel7.setText("Đăng ký các lớp theo mã môn học :");

        btnXemTKB.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnXemTKB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/update.png"))); // NOI18N
        btnXemTKB.setText("Xem TKB");
        btnXemTKB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXemTKBActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(35, 35, 35))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(18, 18, 18)
                        .addComponent(cbbKhoa, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbNK, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnSearch)
                        .addGap(29, 29, 29)
                        .addComponent(btnXemTKB)
                        .addGap(146, 146, 146))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(btnLietke)
                        .addGap(40, 40, 40))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(cbbKhoa, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnLietke, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(cbbNK, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(tfSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSearch)
                    .addComponent(btnXemTKB))
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Danh sách lớp học phần", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 0, 18))); // NOI18N

        tbContent.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Mã lớp HP", "Tên lớp HP", "Mã Khoa", "Mã MH", "Ngày Bắt Đầu", "Ngày Kết Thúc", "Sĩ số", "Chỉ tiêu"
            }
        ));
        jScrollPane1.setViewportView(tbContent);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 774, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnDangKy.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnDangKy.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/accept.png"))); // NOI18N
        btnDangKy.setText("Đăng ký");
        btnDangKy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDangKyActionPerformed(evt);
            }
        });

        btnHuyHP.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnHuyHP.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Button-Delete-icon (1).png"))); // NOI18N
        btnHuyHP.setText("Hủy học phần");
        btnHuyHP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHuyHPActionPerformed(evt);
            }
        });

        btnThoat.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnThoat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Button-Close-icon (2).png"))); // NOI18N
        btnThoat.setText("Thoát");
        btnThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThoatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(240, 240, 240)
                        .addComponent(btnDangKy, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(45, 45, 45)
                        .addComponent(btnHuyHP)
                        .addGap(35, 35, 35)
                        .addComponent(btnThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 806, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnDangKy)
                    .addComponent(btnHuyHP)
                    .addComponent(btnThoat))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnLietkeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLietkeActionPerformed
// TODO add your handling code here:
    try {
        dangkiHP.timLopHP(cbbKhoa.getSelectedItem().toString(), cbbNK.getSelectedItem().toString(), tbContent, tableRecord, tableTitle);
    } catch (Exception e) {
        e.printStackTrace();
    }
}//GEN-LAST:event_btnLietkeActionPerformed

private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
// TODO add your handling code here:
    try {
        dangkiHP.timLopHPByMaMH(tfSearch.getText(), tbContent, tableRecord, tableTitle);
    } catch (Exception e) {
        e.printStackTrace();
    }
}//GEN-LAST:event_btnSearchActionPerformed

private void btnDangKyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDangKyActionPerformed
// TODO add your handling code here:
    if (tbContent.getSelectedRow() > -1) {
        if (JOptionPane.showConfirmDialog(rootPane, "Bạn có thực sự muốn đăng kí lớp này", "Lựa chọn", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
            try {
                dangkiHP.DangkiHP(lbMaSV.getText(), tbContent, tbContent.getSelectedRow());
//                dangkiHP.timLopHP(cbbKhoa.getSelectedItem().toString(), cbbNK.getSelectedItem().toString(), tbContent, tableRecord, tableTitle);
//                System.out.println(loadKetQuaHP());
                loadKetQuaHP();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else {
        JOptionPane.showMessageDialog(rootPane, "Bạn chưa chọn lớp học phần để đăng kí!");
    }
}//GEN-LAST:event_btnDangKyActionPerformed

private void btnHuyHPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHuyHPActionPerformed
// TODO add your handling code here:
    try {
        new frmThoiKhoaBieu(lbMaSV.getText(), lbTenSV.getText(), lbTenlop.getText(), lbNienkhoa.getText(), true, 1).setVisible(true);
        this.setVisible(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
}//GEN-LAST:event_btnHuyHPActionPerformed

private void btnThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThoatActionPerformed
// TODO add your handling code here:
    try {
        this.setVisible(false);
        new frmSinhvien(lbMaSV.getText(), lbTenSV.getText(), lbTenlop.getText(), lbNienkhoa.getText()).setVisible(true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}//GEN-LAST:event_btnThoatActionPerformed

private void btnXemTKBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXemTKBActionPerformed
// TODO add your handling code here:
    try {
        new frmThoiKhoaBieu(lbMaSV.getText(), lbTenSV.getText(), lbTenlop.getText(), lbNienkhoa.getText(), false, 1).setVisible(true);
        this.setVisible(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
}//GEN-LAST:event_btnXemTKBActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmDangKyHocPhan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmDangKyHocPhan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmDangKyHocPhan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmDangKyHocPhan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    new frmDangKyHocPhan().setVisible(true);
                } catch (Exception ex) {
                    Logger.getLogger(frmDangKyHocPhan.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDangKy;
    private javax.swing.JButton btnHuyHP;
    private javax.swing.JButton btnLietke;
    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnThoat;
    private javax.swing.JButton btnXemTKB;
    private javax.swing.JComboBox cbbKhoa;
    private javax.swing.JComboBox cbbNK;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbMaSV;
    private javax.swing.JLabel lbNienkhoa;
    private javax.swing.JLabel lbTenSV;
    private javax.swing.JLabel lbTenlop;
    private javax.swing.JTable tbContent;
    private javax.swing.JTextField tfSearch;
    // End of variables declaration//GEN-END:variables
}
